package com.frank.loadinglibrary.special.dot;

import com.frank.loadinglibrary.special.dot.anim.LoopCircleAnimator;
import com.frank.loadinglibrary.special.dot.anim.SmallAndDropAnimator;
import com.frank.loadinglibrary.special.dot.anim.TextAnimator;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorGroup;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;

/**
 * @author SUQI
 * @date 2021/5/27
 * @description
 **/
public class Controller {
    private LoopCircleAnimator mLoopCircleAnim;
    private SmallAndDropAnimator mSapAnim;
    private TextAnimator mTextAnim;
    private AnimatorGroup mAnimSet;

    public Controller(Component view) {
        initConfig(view);
        mAnimSet = new AnimatorGroup();
        mLoopCircleAnim = new LoopCircleAnimator(view);
        mSapAnim = new SmallAndDropAnimator(view, mLoopCircleAnim.getWolf());
        mTextAnim = new TextAnimator(view);
        // 顺序播放
        mAnimSet.runSerially(mLoopCircleAnim, mSapAnim, mTextAnim);
        mAnimSet.setLoopedCount(Animator.INFINITE);
        mAnimSet.start();
    }

    public void initConfig(Component view) {
        Config.TEXT_SIZE = view.getWidth() / (TextAnimator.STR.length() - 2) / 2;
        float broad = Math.min(view.getWidth(), view.getHeight());
        Config.CENTER_X = view.getWidth() / 2f;
        Config.CENTER_Y = view.getHeight() / 2f;
        Config.START_X = view.getWidth() / 2f;
        Config.START_Y = view.getHeight() / 2f - (broad / 3) + (Config.TEXT_SIZE + 30) / 2f;
        Config.BIG_CIRCLE_RADIUS = view.getHeight() / 2f - Config.START_Y;
    }

    public void draw(Canvas canvas, Paint paint) {
        mLoopCircleAnim.draw(canvas, paint);
        mSapAnim.draw(canvas, paint);
        mTextAnim.draw(canvas, paint);
    }

}
